package top.meijhm.communitymanagement.common.redis;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.meijhm.communitymanagement.common.auth.model.Result;

import javax.annotation.Resource;

@RestController
@RequestMapping("/redis")
@Api
public class RedisController {
    @Resource
    private RedisTemplate<String, String> redisTemplate;

    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public Result save(@ApiParam(value = "字符串键", name = "key", required = true) @RequestParam String key,
                       @ApiParam(value = "字符串值", name = "value", required = true) @RequestParam String value) {
        redisTemplate.opsForValue().set(key, value);
        return Result.succeed(redisTemplate.opsForValue().get(key));
    }
}